home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha Extra 2004 January / CyberMycha Extra 1-2004 (Poland) (Disc 2).bin / Pippi / gmtb.dir / 00002_tbScript.ls < prev    next >
Encoding:
Text File  |  2001-09-12  |  4.7 KB  |  170 lines

  1. property railRects, railLocs, railRots, railPos, railSprites, trainSprites, TrainDrag, occuPiedList, orgList, wholeTrain
  2.  
  3. on new me
  4.   railRects = [rect(350, 244, 450, 344), rect(396, 177, 516, 297), rect(286, 294, 406, 414), rect(281, 181, 401, 301), rect(395, 289, 515, 409), rect(99, 142, 329, 232), rect(465, 135, 695, 225), rect(102, 367, 332, 457), rect(469, 359, 699, 449), rect(650, 177, 740, 407), rect(58, 186, 148, 416)]
  5.   railLocs = [point(535, 169), point(604, 163), point(666, 194), point(706, 250), point(708, 318), point(677, 381), point(618, 416), point(549, 416), point(491, 377), point(336, 236), point(282, 191), point(217, 167), point(150, 183), point(99, 232), point(83, 299), point(102, 366), point(150, 415), point(217, 430), point(284, 413), point(336, 363), point(484, 205)]
  6.   railRots = [-17, 12, 44, 76, 107, 137, 172, 199, 226, 226, 219, 186, 156, 126, 94, 64, 34, 4, -29, -42, -42]
  7.   railPos = [10, 20, 30, 40, 50, 60, 70, 80, 90, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 250]
  8.   railSprites = []
  9.   trainSprites = []
  10.   TrainDrag = 0
  11.   return me
  12. end
  13.  
  14. on reportTrainFrame me
  15.   bigFrame = sprite(trainSprites[1]).frame
  16.   smallFrame = integer(bigFrame * 0.59999999999999998)
  17.   sprite(wholeTrain).frame = smallFrame
  18.   sprite(wholeTrain).loc = point(400, 300)
  19. end
  20.  
  21. on reportSprites me, pSprite, typeX
  22.   if typeX = "railSprites" then
  23.     railSprites[railSprites.count + 1] = pSprite
  24.   else
  25.     if typeX = "trainSprites" then
  26.       trainSprites[trainSprites.count + 1] = pSprite
  27.     else
  28.       if typeX = "wholeTrain" then
  29.         wholeTrain = pSprite
  30.       end if
  31.     end if
  32.   end if
  33. end
  34.  
  35. on takeRect me, pRect
  36.   if railRects.count > 0 then
  37.     X = 0
  38.     repeat with n = 1 to railRects.count
  39.       if pRect = railRects[n] then
  40.         X = 1
  41.         if X = 1 then
  42.           railRects.deleteOne(pRect)
  43.           exit repeat
  44.         end if
  45.       end if
  46.     end repeat
  47.   end if
  48.   if railRects = [] then
  49.     go("train")
  50.   end if
  51.   return X
  52. end
  53.  
  54. on getTrainLoc me, pLoc
  55.   locDifList = []
  56.   repeat with n = 1 to railLocs.count
  57.     if pLoc[1] > railLocs[n][1] then
  58.       A = pLoc[1] - railLocs[n][1]
  59.     else
  60.       A = railLocs[n][1] - pLoc[1]
  61.     end if
  62.     if pLoc[2] > railLocs[n][2] then
  63.       b = pLoc[2] - railLocs[n][2]
  64.     else
  65.       b = railLocs[n][2] - pLoc[2]
  66.     end if
  67.     locDifList[locDifList.count + 1] = A + b
  68.   end repeat
  69.   smallest = 10000
  70.   repeat with n = 1 to locDifList.count
  71.     if locDifList[n] < smallest then
  72.       smallest = locDifList[n]
  73.       position = n
  74.     end if
  75.   end repeat
  76.   check = 0
  77.   if voidp(occuPiedList) = 0 then
  78.     repeat with n = 1 to occuPiedList.count
  79.       if occuPiedList[n] = railPos[position] then
  80.         check = 1
  81.         exit repeat
  82.       end if
  83.     end repeat
  84.   end if
  85.   if check = 0 then
  86.     lastLoc = railLocs[position]
  87.     lastRot = railRots[position]
  88.     lastFrameX = railPos[position]
  89.     return [lastLoc, lastRot, lastFrameX]
  90.   else
  91.     return [0]
  92.   end if
  93. end
  94.  
  95. on placeRects me
  96.   repeat with n = 1 to railRects.count
  97.     sprite(railSprites[n]).rect = railRects[n]
  98.     sprite(railSprites[n]).placed = 1
  99.   end repeat
  100.   go("train")
  101. end
  102.  
  103. on order me
  104.   tramNum = trainSprites.count
  105.   if tramNum > 1 then
  106.     orgList = trainSprites * 1
  107.     sprites = [orgList[1]]
  108.     orgList.deleteAt(1)
  109.     sound(1).play(member("motor4", 1))
  110.     repeat with n = 1 to tramNum - 1
  111.       v = 0
  112.       search(me, orgList[1], orgList[orgList.count], sprite(sprites[sprites.count]).frame)
  113.       v = the result
  114.       if v > 30 then
  115.         sprites[sprites.count + 1] = v
  116.         next repeat
  117.       end if
  118.       cCount = sprites.count + 1
  119.       repeat while sprites.count < cCount
  120.         q = sprites.count
  121.         repeat with b = 1 to q
  122.           sprite(sprites[b]).frame = sprite(sprites[b]).frame - 10
  123.           if sprite(sprites[b]).frame = 1 then
  124.             sprite(sprites[b]).frame = 250
  125.           end if
  126.         end repeat
  127.         updateStage()
  128.         search(me, orgList[1], orgList[orgList.count], sprite(sprites[sprites.count]).frame)
  129.         v = the result
  130.         if v > 30 then
  131.           sprites[sprites.count + 1] = v
  132.         end if
  133.       end repeat
  134.     end repeat
  135.     sound(1).stop()
  136.     sound(1).play(member("connect", 1))
  137.     updateStage()
  138.     repeat while soundBusy(1)
  139.     end repeat
  140.     makeOccupiedList(me, sprites)
  141.   end if
  142. end
  143.  
  144. on makeOccupiedList me, sprites
  145.   occuPiedList = []
  146.   repeat with n = 1 to sprites.count
  147.     occuPiedList[n] = sprite(sprites[n]).frame
  148.   end repeat
  149. end
  150.  
  151. on search me, fromSprite, toSprite, frameX
  152.   yFound = 0
  153.   if frameX < 11 then
  154.     frameY = 250 + frameX - 10
  155.   else
  156.     frameY = frameX - 10
  157.   end if
  158.   repeat with n = fromSprite to toSprite
  159.     if sprite(n).frame = frameY then
  160.       xSprite = n
  161.       yFound = 1
  162.       orgList.deleteOne(n)
  163.       exit repeat
  164.     end if
  165.   end repeat
  166.   if yFound = 1 then
  167.     return xSprite
  168.   end if
  169. end
  170.